package com.grace.cms.forum.user.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.grace.cms.forum.comment.domain.CmsComment;
import com.grace.cms.forum.comment.domain.enums.CommentVisibleEnums;
import com.grace.cms.forum.comment.domain.properties.OlyCommentProperties;
import com.grace.cms.forum.comment.domain.vo.CmsCommentVo;
import com.grace.cms.forum.comment.service.ICmsCommentService;
import com.grace.cms.forum.user.service.IHandCommentService;
import com.github.pagehelper.PageHelper;
import com.grace.system.service.impl.SysSearchConfigServiceImpl;
import com.grace.cms.common.enums.RecordTypeEnums;
import com.grace.cms.common.model.support.PageData;

@Service
public class HandCommentServiceImpl implements IHandCommentService {

    @Autowired
    private ICmsCommentService cmsCommentService;

    @Autowired
    private SysSearchConfigServiceImpl configService;

    @Override
    public boolean commentSupport(RecordTypeEnums recordType) {
        return "true".equals(configService.selectConfigDefaultValue(
                OlyCommentProperties.COMMENT_CONFIG_GROUP.defaultValue(),
                OlyCommentProperties.getEnum("COMMENT_OPEN_" + recordType.name())));

    }

    public PageData<CmsCommentVo> pageComment(String recordId, Long parentId, RecordTypeEnums recordType,
            Long orderNum, String themeName, String onlyCode, int pageNum, int pageSize) {
        CmsComment cmsComment = new CmsComment();
        cmsComment.setRecordId(recordId);
        cmsComment.setOrderNum(orderNum);
        cmsComment.setVisible(CommentVisibleEnums.PASS.ordinal());
        cmsComment.setRecordType(recordType==null?null:recordType.ordinal());
        cmsComment.setParentId(parentId);
        cmsComment.setThemeName(themeName);
        cmsComment.setOnlyCode(onlyCode);
        PageHelper.startPage(pageNum, pageSize, "create_time desc");
        return PageData.getData(cmsCommentService.listCmsCommentVo(cmsComment), 200);
    }

    public CmsCommentVo selectCmsCommentVoById(Long commentId) {
        return cmsCommentService.selectCmsCommentVoById(commentId);
    }
}
